{$header}
<div id="main" class="main" >
    <div class="content">
  <h3 class="heading">批量入库 [ <a href="__URL__">返回列表</a> ]</h3>
<div id="result" class="result none"></div>
<table>
    <tr>
            <td class="tRight" >模板下载：</td>
            <td class="tLeft" >
                <a href="__PUBLIC__/Uploads/采购导入模板.xls"><i class="icon-download-alt"></i>采购导入模板</a>
            </td>
</tr>
<form name="form" action="" method="POST" enctype="multipart/form-data">
<tr>
    <td>上传文件：</td>
    <td>
        <input id="fileToUpload" type="file" size="45" name="upload" class="input">
        <a class="btn btn-primary" onClick="return ajaxFileUpload();">批量导入</a>
    </td>
</tr>
</form>
</table>
<form class="form-horizontal well" method='post' id="form1" name="form1" action="__URL__/insert/">
<table cellpadding=3 cellspacing=3 >
 <tr>
    <td class="tRight" width="150px">采购单号：</td>
    <td class="span9" >
            <input  class="large" name="enter_no" value="{:D('Enter')->getNO()}">
            入库时间：<input type="text" class="span2" name="create_time" value="{:toDate(time())}" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
        </td>
</tr>
<tr>
    <td class="tRight" width="150px">按<b>条码</b>查询产品：</td>
    <td class="tLeft" >
            <input id="ptm" name="ptm_id" style="width:500px"></input><a class="btn btn-info" href="javascript:void(0)" onclick="showdetail('ptm','buy');">添加产品</a>
        </td>
</tr>
<tr>
    <td class="tRight" >按<b>拼音人工编码</b>查询产品：</td>
    <td class="tLeft" >
            <input id="ppy" name="ppy_id" style="width:500px"></input>
            <a class="btn btn-info" href="javascript:void(0)" onclick="showdetail('ppy','buy');">添加产品</a>
        </td>
</tr>
<tr>
    <td class="tRight" >按<b>汉字</b>查询产品：</td>
    <td class="tLeft" >
            <div class="input-append">
                <input id="q" name="q" class="input-xxlarge search-query" placeholder="搜索"><input id="hz" name="hz_id" type="hidden"></input>
                <button class="btn" type="button" onclick="filter('enter','buy')"><i class="icon-search"></i>搜索</button>
                <span class="help-inline alert">支持空格查询,如:名称 + 度数</span>
            </div>
        </td>
</tr>

<tr>
	<td class="tRight" width="150px">待入库产品：</td>
        <td class="tLeft">
            <table id="chosed_product" name="ptable" class="table table-bordered table-striped">
                <thead><tr><th width="85px">条码</th><th width="200px">名称</th><th>规格</th> <th>进价</th><th>数量</th><th>单位</th><th>库存</th><th width="75px">生产批号</th><th width="75px">截止有效期</th> <th>删除</th></tr></thead>
            </table>
        </td>
</tr>
<tr>
	<td class="tRight" >经办人：</td>
	<td class="tLeft" >
            <select name="user_id" class="span2">
                <volist name="users" id="us">
                <option value="{$key}" <eq name="_SESSION[C('USER_AUTH_KEY')]" value="$key">selected</eq> >{$us}</option>
                </volist>
            </select>
            仓库：<select name="warehouse_id" class="span2">
                <volist name="warehouses" id="wh">
                    <option value="{$key}" <eq name="key" value="1">selected</eq>>{$wh}</option>
                </volist>
            </select>
            
            
            </td></tr>
            <tr><td>供应商</td><td><select name="supplier_id" class="span2">
                <volist name="suppliers" id="sp">
                    <option value="{$key}" >{$sp}</option>
                </volist>
            </select>
        </td>
</tr>
<tr>
    <td class="tRight">备注：</td>
        <td class="tLeft"><textarea class="span12" name="remark" rows="2"></textarea>
        </td>
</tr>
<tr>
	<td></td>
	<td class="center" width="300">
	<button type="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> 保存</button>
	<a class="btn btn-primary offset1" href="__URL__"><i class="icon-arrow-left icon-white"></i>返回</a>
	</td>
</tr>
</table>
</form>
</div>
</div>
<include file="Public:footer" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/easyui/themes/default/easyui.css">
<script type="text/javascript" src="__PUBLIC__/Js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/filter-product.js"></script>
<load href="__PUBLIC__/Js/My97DatePicker/WdatePicker.js" />

<script type="text/javascript" src="__PUBLIC__/Js/ajaxfileupload.js"></script>

<script type="text/javascript">
    function ajaxFileUpload()
    {
        $("#loading")
        .ajaxStart(function(){
            $(this).show();
        })
        .ajaxComplete(function(){
            $(this).hide();
        });

        $.ajaxFileUpload
        (
            {
                url:URL+'/import',
                secureuri:false,
                fileElementId:'fileToUpload',
                dataType: 'json',
                data:{name:'logan', id:'id'},
                success: function (data, status)
                {
                    if(typeof(data.error) != 'undefined')
                    {
                        if(data.error != '')
                        {
                            alert(data.error);
                        }else
                        {
                            var msg = URLdecode(data.msg);

                            $('#chosed_product').append(msg);
                        }
                    }
                },
                error: function (data, status, e)
                {
                    alert(e);
                }
            }
        )
        
        return false;

    }

function URLdecode(str) {
        var ret = "";
        for(var i=0;i<str.length;i++) {
                var chr = str.charAt(i);
                if(chr == "+") {
                        ret += " ";
                }else if(chr=="%") {
                        var asc = str.substring(i+1,i+3);
                        if(parseInt("0x"+asc)>0x7f) {
                                ret += decodeURI("%"+ str.substring(i+1,i+9));
                                i += 8;
                        }else {
                                ret += String.fromCharCode(parseInt("0x"+asc));
                                i += 2;
                        }
                }else {
                        ret += chr;
                }
        }
        return ret;
}
</script>